package com.catmiw.wyz;

import java.util.ArrayList;
import java.util.List;

public class PrimeUtil {
	public static void print(int[] t){
		for (int i=0;i<t.length;i++){
			System.out.print(t[i]+"\t");
			if (i%10==0)
				System.out.println("");
		}
	}
	public static List<Integer> allPrime(int limit){
		List<Integer> result=new ArrayList<Integer>();
		int[] temp=new int[limit+1];
		for (int i=2;i<=limit;i++){
			temp[i]=i;
		}
		int now=2;
		while (now<limit){
			System.out.println(now);
			//print(temp);
			for (int i=2;i<=limit/now;i++){
				temp[i*now]=0;
			}
			while(++now<limit&&temp[now]==0){
				System.out.println(now+"\t"+temp[now]);
			}
		}
		
		for (int i=2;i<=limit;i++){
			if (temp[i]!=0)
				result.add(temp[i]);
		}
		
		return result;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		List<Integer> list=allPrime(1000);
		int last=0;
		for (Integer i:list){
			int j=i.intValue();
			System.out.println(i+"\t"+(j-last));
			last=j;
		}

	}

}
